#include <stdafx.h>
#include <iostream>
#include <conio.h>

class Matematyka
  {
  	public:  		
  	Matematyka(const int a);
  	 double *x;
	 void Rozwiaz(double **A,double *B);
  	~Matematyka();
  	
  	private:
  	int n;
 	
  };
  
  Matematyka::Matematyka(const int a) : n(a)
  {
	x = new double[a];
  }
 
 Matematyka::~Matematyka()
 {
	delete x;
 }


  void Matematyka::Rozwiaz(double **A,double *B)
  {
	
    double **tmpA;
	tmpA = new double*[n];

	for (int i=0;i<n;i++)
	{
		tmpA[i] = new double[n+1];
	}

    double tmp = 0;
	
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {

            tmpA[i][j] = A[i][j];
        }
        tmpA[i][n] = B[i];
    }

    for (int k = 0; k < n; k++)
    {
        tmp = tmpA[k][k];
        for (int i = 0; i < n + 1; i++)
        {
            tmpA[k][i] = tmpA[k][i] / tmp;
        }

        for (int i = 0; i < n; i++)
        {
            if (i != k)
            {
                tmp = tmpA[i][k] / tmpA[k][k];
                for (int j = k; j < n + 1; j++)
                {
                    tmpA[i][j] -= tmp * tmpA[k][j];
                }
            }
        }
    }

    for (int i = 0; i < n; i++)
    {
        x[i] = tmpA[i][n];
    }

	delete tmpA;

  }
  

int main(int argc, char *argv[])
{
	double **A;
	double *B;
	int n = 3;	
	
	A = new double*[3];
	for(int i=0;i<3;i++)
		A[i]=new double[3];
		
	B = new double[3];

	A[0][0]=1;
	A[0][1]=0;
	A[0][2]=3;
	A[1][0]=2;
	A[1][1]=1;
	A[1][2]=1;
	A[2][0]=-3;
	A[2][1]=2;
	A[2][2]=-2;

	B[0]=7;
	B[1]=4;
	B[2]=-10;

   Matematyka mat1(n);
   mat1.Rozwiaz(A,B);
    
    for (int i=0;i<3;i++)
    	std::cout<<mat1.x[i]<<std::endl;
    	
    _getch();
    
	return 0;
} 
